package cn.ryh.gat1400.service.impl;


import cn.hutool.core.lang.UUID;
import cn.ryh.gat1400.core.Response;
import cn.ryh.gat1400.model.Face;
import cn.ryh.gat1400.model.FaceListObject;
import cn.ryh.gat1400.model.ResponseStatus;
import cn.ryh.gat1400.model.ResponseStatusListModeObject;
import cn.ryh.gat1400.service.FaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: aiLin
 * @Date: 2020/10/9 15:24
 * @desc: 人脸对象接口实现
 */
@Slf4j
@Service
public class FaceServiceImpl implements FaceService {
    // @Resource
    // private FacedbMapper facedbMapper;
    // @Resource
    // private FeignSubImageInfoCore feignSubImageInfoCore;

    /**
     * 批量人脸新增
     * @param faceListObject
     * @return
     */
    @Override
    public ResponseStatusListModeObject addFace(FaceListObject faceListObject) {
        String reqUrl = "/VIID/Faces";
        List<ResponseStatus> resp3 = new ArrayList<>();
        ResponseStatus r = new ResponseStatus();
        List<Face> faceList = faceListObject.getFaceObject().getFaceList();
        if(faceList!=null && faceList.size()>0){
            for(int i=0;i<faceList.size();i++){
                Face face = faceList.get(i);
                // List<SubImageInfo> subImageInfo = face.getSubImageInfoList().getSubImageInfo();
                // new Thread(() -> {
                //     SubImageInfoCore.getSubImageInfo(subImageInfo);
                // }).start();
                // //new Thread(() -> {
                //     feignSubImageInfoCore.getSubImageInfo(subImageInfo,faceListObject);
                // //}).start();
                // try {
                //     Facedb facedb = (Facedb) BenUtils.beanTobeanLowerCase(face, Facedb.class);
                //     facedb.setCreateBy("admin");
                //     facedb.setCreateTime(DateUtils.getNowDate());
                //     facedb.setSubimageinfolist(JSON.toJSONString(faceListObject));
                //     facedb.setCriminalInvolvedSpeciCode(face.getCriminalInvolvedSpecilisationCode());
                //     int mark = facedbMapper.insertFacedb(facedb);
                //     if(mark>=1){
                //         r = Response.getResponOk(facedb.getFaceid(),reqUrl,"成功");
                //     }else{
                //         r = Response.getResponError(facedb.getFaceid(),reqUrl,"新增失败");
                //     }
                // } catch (Exception e) {
                //     if(String.valueOf(e).contains("唯一")){
                //         log.error("人脸数据：{}，已存在，不重新记录",face.getFaceID());
                //         r = Response.getResponOk(face.getFaceID(),reqUrl,"人脸数据："+face.getFaceID()+"，已存在，不重新记录");
                //     }else{
                //         r = Response.getResponOk(face.getFaceID(),reqUrl,"人脸数据："+face.getFaceID()+"，异常，存入记录表");
                //     }
                // }
                r = Response.getResponOk(UUID.randomUUID().toString(),reqUrl,"成功");
            }
        }
        resp3.add(r);
        return Response.ok(resp3);
    }

    /***
     * 批量查询
     * @param FaceID
     * @param InfoKind
     * @param IDType
     * @param SourceID
     * @param DeviceID
     * @param Name
     * @return
     */
    @Override
    public ResponseStatusListModeObject seleteFace(String FaceID, String InfoKind, String IDType, String SourceID, String DeviceID, String Name) {
        // Facedb face = new Facedb();
        // face.setFaceid(FaceID!=null ? FaceID : "");
        // facedbMapper.selectFacedbList(face);
        return null;
    }
}
